﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GDI_AnalysisComponents
{
    //两单元连线类
    [Serializable()]
    public class GLinkGUnits
    {
        private GUnit startGun;
        private GUnit endGun;

        public GLinkGUnits(GUnit startGun, GUnit endGun)
        {
            this.startGun = startGun;
            this.endGun = endGun;
        }

        public GUnit StartGun
        {
            get { return startGun; }
            set { startGun = value; }
        }

        public GUnit EndGun
        {
            get { return endGun; }
            set { endGun = value; }
        }

        public GLine GetGLine()
        {
            CreateGLine cg = new CreateGLine();
            GLine gl = cg.ShortLine(startGun.GetRightMidPoint(), startGun.GetLeftMidPoint(), endGun.GetRightMidPoint(), endGun.GetLeftMidPoint());
            return gl;
        }

        public void DrawRedGLine(Graphics g)
        {
            Pen pen = new Pen(Color.Red,2);
            pen.DashStyle = DashStyle.DashDotDot;
            CreateGLine cg = new CreateGLine();
            GLine gl = cg.ShortLine(startGun.GetRightMidPoint(), startGun.GetLeftMidPoint(), endGun.GetRightMidPoint(), endGun.GetLeftMidPoint());
            gl.Pen = pen;
            gl.DrawGLine(g);
            GraphicsPath gp = new GraphicsPath();
            gp.AddLine(gl.StartPt.X, gl.StartPt.Y, gl.EndPt.X, gl.EndPt.Y);
            PointF[] p = gp.PathPoints;
            for (int j = 0; j < gp.PointCount; j++)
            {
                g.FillRectangle(Brushes.Red, p[j].X - 3, p[j].Y - 3, 6, 6);
            }
        }
        public void DrawBlueGLine(Graphics g)
        {
            Pen pen = new Pen(Color.Blue);
            CreateGLine cg = new CreateGLine();
            GLine gl = cg.ShortLine(startGun.GetRightMidPoint(), startGun.GetLeftMidPoint(), endGun.GetRightMidPoint(), endGun.GetLeftMidPoint());
            gl.Pen = pen;
            gl.DrawGLine(g);
        }
    }
}
